package com.example.websocket.xml;

import com.example.websocket.xml.bean.CustomCodeModel;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/sax")
public class SaxController {

    @RequestMapping(value = "/output", method = RequestMethod.POST)
    public FileOutputStream output() throws FileNotFoundException {
        List<CustomCodeModel> tree = new ArrayList<>();
        CustomCodeModel tree1 = new CustomCodeModel();
        tree1.setOLD_BM(1111L);
        tree1.setOLD_PID(1111L);
        tree1.setMC("1111");
        tree1.setPID(1111L);
        CustomCodeModel tree2 = new CustomCodeModel();
        tree2.setOLD_BM(222L);
        tree2.setOLD_PID(2222L);
        tree2.setMC("2222");
        tree2.setPID(2222L);
        tree.add(tree1);
        tree.add(tree2);
        List<CustomCodeModel> children = new ArrayList<>();
        CustomCodeModel children1 = new CustomCodeModel();
        children1.setOLD_BM(1111L);
        children1.setOLD_PID(1111L);
        children1.setMC("1111");
        children1.setPID(1111L);
        children.add(children1);
        File file = new File("test.xml");
        new SaxParseTaxCode().createXMLBySAX(tree, children, file);
        return new FileOutputStream(file);
    }

}
